package cn.kane.command;

import java.util.ArrayList;
import java.util.List;

public class Invoker {

	private List<ICommand> cmdLst = new ArrayList<ICommand>(10);
	private int position = 0 ;
	private ICalendar calendar = new Calendar();
	
	public void calc(char operator,int value){
		ICommand command = new Command(calendar,operator,value);
		command.execute();
		cmdLst.add(command);
		position = cmdLst.size() ;
	}
	
	public void undo(int level){
		for(int i=0;i<level;i++){
			if(position>0){
				ICommand command = cmdLst.get(--position);
				command.undo();
			}
		}
	}
	
	public void redo(int level){
		for(int i =0 ; i<level ; i++){
			if(position < cmdLst.size()){
				ICommand command = cmdLst.get(position++);
				command.execute();
			}
		}
	}
	
}
